home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Programming / powerd / examples / FergusonOLD.d < prev    next >
Encoding:
Text File  |  2000-02-03  |  1.4 KB  |  59 lines

  1. // Ferguson.d - example of how to generate ferguson's kubics (curves) in D
  2.  
  3. MODULE    'intuition/intuition',
  4.             'utility/tagitem'
  5.  
  6. PROC main()
  7.     DEF w:PTR TO Window
  8.     IF w:=OpenWindowTags(NIL,
  9.             WA_InnerWidth,320,
  10.             WA_InnerHeight,320,
  11.             WA_IDCMP,IDCMP_CLOSEWINDOW,
  12.             WA_Flags,WFLG_DRAGBAR|WFLG_GIMMEZEROZERO|WFLG_RMBTRAP|WFLG_ACTIVATE|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET,
  13.             WA_Title,'Ferguson''s Cubic',
  14.             TAG_END)
  15.     
  16.         Ferguson(w.RPort,
  17.           -5.0,  0.0,  // position of point A
  18.          -10.0, 10.0,  // vector in point A
  19.            5.0,  0.0,  // position of point B
  20.          -10.0,-10.0,  // vector in point B
  21.           1000)            // # of intersections
  22.     
  23.         WaitPort(w.UserPort)
  24.         CloseWindow(w)
  25.     ENDIF
  26. ENDPROC
  27.  
  28. /*
  29.     rp            - window rastport
  30.     xA,yA        - coordinates of point A
  31.     xa,ya        - vector in point A
  32.     xB,yB        - coordinates of point B
  33.     xb,yb        - vector in point B
  34.     steps        - number of intersections
  35. */
  36. PROC Ferguson(rp,xA:FLOAT,yA:FLOAT,xa:FLOAT,ya:FLOAT,xB:FLOAT,yB:FLOAT,xb:FLOAT,yb:FLOAT,steps)
  37.     DEFF    delta,t,x,y,f0,f1,f2,f3
  38.     DEF    i
  39.     delta:=1.0/steps
  40.     SetAPen(rp,1)
  41.     x:=xA*20.0
  42.     y:=yA*-20.0
  43.     Move(rp,x+160,y+160)
  44.     FOR i:=0 TO steps
  45.         t:=delta*i
  46.         f0:=2.0*t*t*t-3.0*t*t+1.0        // Ferguson's polynoms
  47.         f1:=-2.0*t*t*t+3.0*t*t
  48.         f2:=t*t*t-2.0*t*t+t
  49.         f3:=t*t*t-t*t
  50.         x:=xA*f0+xB*f1+xa*f2+xb*f3        // parametrical representations for x and y coords
  51.         y:=yA*f0+yB*f1+ya*f2+yb*f3
  52.         x*=20.0
  53.         y*=-20.0
  54.         Draw(rp,x+160,y+160)
  55.     ENDFOR
  56. ENDPROC
  57.  
  58. // MarK 7/8/99
  59.